﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 脚本功能： 管理  公共部分的 Bg Pretab
/// 添加对象： BgCommonPanel  预设体
/// </summary>
public class BgCommonPanel : MonoBehaviour {


    #region 数据定义和unity自带方法组
    public static BgCommonPanel mInstance;

    private TitlePosShowCtr mTitlePosShowCtr;
    private MenuPanelCtr mMenuPanelCtr;
    private CommonBtnsCtr mCommonBtnsCtr;

    private GameObject mCommonBtnsGo, mMenuPanelGo, mTitlePosShowGo;
    private Image mBgImage;
    void Awake()
    {
        mInstance = this;
        FindGo();
        BindingScript();
    }


    void Start () {
		
	}

    #endregion


    #region  私有方法组
    private void FindGo()
    {
        if (mCommonBtnsGo == null)
        {
            mCommonBtnsGo = TransformHelper.FindChild(transform, "CommonBtnsCtr");
        }
        if (mMenuPanelGo == null)
        {
            mMenuPanelGo = TransformHelper.FindChild(transform, "MenuPanelCtr");
        }
        if (mTitlePosShowGo == null)
        {
            mTitlePosShowGo = TransformHelper.FindChild(transform, "TitlePosShowCtr");
        }
        if (mBgImage == null)
        {
            mBgImage = GetComponent<Image>();
        }
    }

    private void BindingScript()
    {
        if (mCommonBtnsGo != null || mCommonBtnsCtr == null)
        {
            mCommonBtnsCtr = mCommonBtnsGo.GetComponent<CommonBtnsCtr>();
            if (mCommonBtnsCtr == null)
            {
                mCommonBtnsCtr = mCommonBtnsGo.AddComponent<CommonBtnsCtr>();
            }
        }

        if (mMenuPanelGo != null || mMenuPanelCtr == null)
        {
            mMenuPanelCtr = mMenuPanelGo.GetComponent<MenuPanelCtr>();
            if (mMenuPanelCtr == null)
            {
                mMenuPanelCtr = mMenuPanelGo.AddComponent<MenuPanelCtr>();
            }
        }

        if (mTitlePosShowGo != null || mTitlePosShowCtr == null)
        {
            mTitlePosShowCtr = mTitlePosShowGo.GetComponent<TitlePosShowCtr>();
            if (mTitlePosShowCtr == null)
            {
                mTitlePosShowCtr = mTitlePosShowGo.AddComponent<TitlePosShowCtr>();
            }
        }
    }
    #endregion


    #region  公有方法组
    public CommonBtnsCtr GetCommonBtnsCtr()
    {
        if (mCommonBtnsCtr == null)
        {
            FindGo();
            BindingScript();
        }
        return mCommonBtnsCtr;
    }

    public TitlePosShowCtr GetTitlePosShowCtr()
    {
        if (mTitlePosShowCtr == null)
        {
            FindGo();
            BindingScript();
        }
        return mTitlePosShowCtr;
    }

    public MenuPanelCtr GetMenuPanelCtr()
    {
        if (mMenuPanelCtr == null)
        {
            FindGo();
            BindingScript();
        }
        return mMenuPanelCtr;
    }

    /// <summary>
    /// 设置整个图片的背景 以后就是几种图片的替换 还有就是 不显示这个图片
    /// </summary>
    public void SetBgImage(Sprite sp)
    {
        mBgImage.enabled = true;
        if (sp == null)
        {
            mBgImage.enabled = false;
            return;
        }
        mBgImage.sprite = sp;
    }

   
    #endregion


}
